<template>
  <el-dialog title="核销" width="30%" :close-on-click-modal="false" :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit('dataForm')" label-width="80px">
      <el-form-item label="核销码" prop="verification">
        <div class="flex">
          <el-input v-model="dataForm.verification" placeholder="请输入核销码"></el-input>
          <!-- <el-button class="ml10">查询</el-button> -->
        </div>
      </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit('dataForm')">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
import orderService from '@/api/orderService.js'
export default {
  data () {
    return {
      visible: false,
      dataForm: {
        verification: ''
      },
      dataRule: {
        verification: [{
          required: true,
          message: '核销码不能为空',
          trigger: 'blur'
        }]
      }
    }
  },

  methods: {
    init () {
      this.visible = true
    },
    dataFormSubmit (e) {
      this.$refs[e].validate((valid) => {
        if (valid) {
          orderService.verification(this.dataForm).then(res => {
            if (res.data && res.data.code == 200) {
              this.$message.success('核销成功！')
              this.$emit('result', res.data.data)
            }
          })
        } else {
          console.log('error submit!!')
          return false
        }
      })
    }
  }
}
</script>

<style lang="scss">
.flex {
  display: flex;
}

.ml10 {
  margin-left: 10px;
}
</style>
